package com.vshining.cryptoki;

import java.util.HashMap;
import java.util.Map;

/**
 * CK_RV
 *
 * @author Shining Wang <shiningwang@vshining.com>
 */
@SuppressWarnings("unused")
public abstract class CryptokiResultValue {
    protected static final Map<String, Long> ncMap = new HashMap<String, Long>(87);
    protected static final Map<Long, String> cnMap = new HashMap<Long, String>(87);

    static {
        ncMap.put("CKR_OK", 0x00000000L);
        ncMap.put("CKR_CANCEL", 0x00000001L);
        ncMap.put("CKR_HOST_MEMORY", 0x00000002L);
        ncMap.put("CKR_SLOT_ID_INVALID", 0x00000003L);
        ncMap.put("CKR_GENERAL_ERROR", 0x00000005L);
        ncMap.put("CKR_FUNCTION_FAILED", 0x00000006L);
        ncMap.put("CKR_ARGUMENTS_BAD", 0x00000007L);
        ncMap.put("CKR_NO_EVENT", 0x00000008L);
        ncMap.put("CKR_NEED_TO_CREATE_THREADS", 0x00000009L);
        ncMap.put("CKR_CANT_LOCK", 0x0000000AL);
        ncMap.put("CKR_ATTRIBUTE_READ_ONLY", 0x00000010L);
        ncMap.put("CKR_ATTRIBUTE_SENSITIVE", 0x00000011L);
        ncMap.put("CKR_ATTRIBUTE_TYPE_INVALID", 0x00000012L);
        ncMap.put("CKR_ATTRIBUTE_VALUE_INVALID", 0x00000013L);
        ncMap.put("CKR_DATA_INVALID", 0x00000020L);
        ncMap.put("CKR_DATA_LEN_RANGE", 0x00000021L);
        ncMap.put("CKR_DEVICE_ERROR", 0x00000030L);
        ncMap.put("CKR_DEVICE_MEMORY", 0x00000031L);
        ncMap.put("CKR_DEVICE_REMOVED", 0x00000032L);
        ncMap.put("CKR_ENCRYPTED_DATA_INVALID", 0x00000040L);
        ncMap.put("CKR_ENCRYPTED_DATA_LEN_RANGE", 0x00000041L);
        ncMap.put("CKR_FUNCTION_CANCELED", 0x00000050L);
        ncMap.put("CKR_FUNCTION_NOT_PARALLEL", 0x00000051L);
        ncMap.put("CKR_FUNCTION_NOT_SUPPORTED", 0x00000054L);
        ncMap.put("CKR_KEY_HANDLE_INVALID", 0x00000060L);
        ncMap.put("CKR_KEY_SIZE_RANGE", 0x00000062L);
        ncMap.put("CKR_KEY_TYPE_INCONSISTENT", 0x00000063L);
        ncMap.put("CKR_KEY_NOT_NEEDED", 0x00000064L);
        ncMap.put("CKR_KEY_CHANGED", 0x00000065L);
        ncMap.put("CKR_KEY_NEEDED", 0x00000066L);
        ncMap.put("CKR_KEY_INDIGESTIBLE", 0x00000067L);
        ncMap.put("CKR_KEY_FUNCTION_NOT_PERMITTED", 0x00000068L);
        ncMap.put("CKR_KEY_NOT_WRAPPABLE", 0x00000069L);
        ncMap.put("CKR_KEY_UNEXTRACTABLE", 0x0000006AL);
        ncMap.put("CKR_MECHANISM_INVALID", 0x00000070L);
        ncMap.put("CKR_MECHANISM_PARAM_INVALID", 0x00000071L);
        ncMap.put("CKR_OBJECT_HANDLE_INVALID", 0x00000082L);
        ncMap.put("CKR_OPERATION_ACTIVE", 0x00000090L);
        ncMap.put("CKR_OPERATION_NOT_INITIALIZED", 0x00000091L);
        ncMap.put("CKR_PIN_INCORRECT", 0x000000A0L);
        ncMap.put("CKR_PIN_INVALID", 0x000000A1L);
        ncMap.put("CKR_PIN_LEN_RANGE", 0x000000A2L);
        ncMap.put("CKR_PIN_EXPIRED", 0x000000A3L);
        ncMap.put("CKR_PIN_LOCKED", 0x000000A4L);
        ncMap.put("CKR_SESSION_CLOSED", 0x000000B0L);
        ncMap.put("CKR_SESSION_COUNT", 0x000000B1L);
        ncMap.put("CKR_SESSION_HANDLE_INVALID", 0x000000B3L);
        ncMap.put("CKR_SESSION_PARALLEL_NOT_SUPPORTED", 0x000000B4L);
        ncMap.put("CKR_SESSION_READ_ONLY", 0x000000B5L);
        ncMap.put("CKR_SESSION_EXISTS", 0x000000B6L);
        ncMap.put("CKR_SESSION_READ_ONLY_EXISTS", 0x000000B7L);
        ncMap.put("CKR_SESSION_READ_WRITE_SO_EXISTS", 0x000000B8L);
        ncMap.put("CKR_SIGNATURE_INVALID", 0x000000C0L);
        ncMap.put("CKR_SIGNATURE_LEN_RANGE", 0x000000C1L);
        ncMap.put("CKR_TEMPLATE_INCOMPLETE", 0x000000D0L);
        ncMap.put("CKR_TEMPLATE_INCONSISTENT", 0x000000D1L);
        ncMap.put("CKR_TOKEN_NOT_PRESENT", 0x000000E0L);
        ncMap.put("CKR_TOKEN_NOT_RECOGNIZED", 0x000000E1L);
        ncMap.put("CKR_TOKEN_WRITE_PROTECTED", 0x000000E2L);
        ncMap.put("CKR_UNWRAPPING_KEY_HANDLE_INVALID", 0x000000F0L);
        ncMap.put("CKR_UNWRAPPING_KEY_SIZE_RANGE", 0x000000F1L);
        ncMap.put("CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT", 0x000000F2L);
        ncMap.put("CKR_USER_ALREADY_LOGGED_IN", 0x00000100L);
        ncMap.put("CKR_USER_NOT_LOGGED_IN", 0x00000101L);
        ncMap.put("CKR_USER_PIN_NOT_INITIALIZED", 0x00000102L);
        ncMap.put("CKR_USER_TYPE_INVALID", 0x00000103L);
        ncMap.put("CKR_USER_ANOTHER_ALREADY_LOGGED_IN", 0x00000104L);
        ncMap.put("CKR_USER_TOO_MANY_TYPES", 0x00000105L);
        ncMap.put("CKR_WRAPPED_KEY_INVALID", 0x00000110L);
        ncMap.put("CKR_WRAPPED_KEY_LEN_RANGE", 0x00000112L);
        ncMap.put("CKR_WRAPPING_KEY_HANDLE_INVALID", 0x00000113L);
        ncMap.put("CKR_WRAPPING_KEY_SIZE_RANGE", 0x00000114L);
        ncMap.put("CKR_WRAPPING_KEY_TYPE_INCONSISTENT", 0x00000115L);
        ncMap.put("CKR_RANDOM_SEED_NOT_SUPPORTED", 0x00000120L);
        ncMap.put("CKR_RANDOM_NO_RNG", 0x00000121L);
        ncMap.put("CKR_DOMAIN_PARAMS_INVALID", 0x00000130L);
        ncMap.put("CKR_BUFFER_TOO_SMALL", 0x00000150L);
        ncMap.put("CKR_SAVED_STATE_INVALID", 0x00000160L);
        ncMap.put("CKR_INFORMATION_SENSITIVE", 0x00000170L);
        ncMap.put("CKR_STATE_UNSAVEABLE", 0x00000180L);
        ncMap.put("CKR_CRYPTOKI_NOT_INITIALIZED", 0x00000190L);
        ncMap.put("CKR_CRYPTOKI_ALREADY_INITIALIZED", 0x00000191L);
        ncMap.put("CKR_MUTEX_BAD", 0x000001A0L);
        ncMap.put("CKR_MUTEX_NOT_LOCKED", 0x000001A1L);
        ncMap.put("CKR_NEW_PIN_MODE", 0x000001B0L);
        ncMap.put("CKR_NEXT_OTP", 0x000001B1L);
        ncMap.put("CKR_FUNCTION_REJECTED", 0x00000200L);
        ncMap.put("CKR_VENDOR_DEFINED", 0x80000000L);

        cnMap.put(0x00000000L, "CKR_OK");
        cnMap.put(0x00000001L, "CKR_CANCEL");
        cnMap.put(0x00000002L, "CKR_HOST_MEMORY");
        cnMap.put(0x00000003L, "CKR_SLOT_ID_INVALID");
        cnMap.put(0x00000005L, "CKR_GENERAL_ERROR");
        cnMap.put(0x00000006L, "CKR_FUNCTION_FAILED");
        cnMap.put(0x00000007L, "CKR_ARGUMENTS_BAD");
        cnMap.put(0x00000008L, "CKR_NO_EVENT");
        cnMap.put(0x00000009L, "CKR_NEED_TO_CREATE_THREADS");
        cnMap.put(0x0000000AL, "CKR_CANT_LOCK");
        cnMap.put(0x00000010L, "CKR_ATTRIBUTE_READ_ONLY");
        cnMap.put(0x00000011L, "CKR_ATTRIBUTE_SENSITIVE");
        cnMap.put(0x00000012L, "CKR_ATTRIBUTE_TYPE_INVALID");
        cnMap.put(0x00000013L, "CKR_ATTRIBUTE_VALUE_INVALID");
        cnMap.put(0x00000020L, "CKR_DATA_INVALID");
        cnMap.put(0x00000021L, "CKR_DATA_LEN_RANGE");
        cnMap.put(0x00000030L, "CKR_DEVICE_ERROR");
        cnMap.put(0x00000031L, "CKR_DEVICE_MEMORY");
        cnMap.put(0x00000032L, "CKR_DEVICE_REMOVED");
        cnMap.put(0x00000040L, "CKR_ENCRYPTED_DATA_INVALID");
        cnMap.put(0x00000041L, "CKR_ENCRYPTED_DATA_LEN_RANGE");
        cnMap.put(0x00000050L, "CKR_FUNCTION_CANCELED");
        cnMap.put(0x00000051L, "CKR_FUNCTION_NOT_PARALLEL");
        cnMap.put(0x00000054L, "CKR_FUNCTION_NOT_SUPPORTED");
        cnMap.put(0x00000060L, "CKR_KEY_HANDLE_INVALID");
        cnMap.put(0x00000062L, "CKR_KEY_SIZE_RANGE");
        cnMap.put(0x00000063L, "CKR_KEY_TYPE_INCONSISTENT");
        cnMap.put(0x00000064L, "CKR_KEY_NOT_NEEDED");
        cnMap.put(0x00000065L, "CKR_KEY_CHANGED");
        cnMap.put(0x00000066L, "CKR_KEY_NEEDED");
        cnMap.put(0x00000067L, "CKR_KEY_INDIGESTIBLE");
        cnMap.put(0x00000068L, "CKR_KEY_FUNCTION_NOT_PERMITTED");
        cnMap.put(0x00000069L, "CKR_KEY_NOT_WRAPPABLE");
        cnMap.put(0x0000006AL, "CKR_KEY_UNEXTRACTABLE");
        cnMap.put(0x00000070L, "CKR_MECHANISM_INVALID");
        cnMap.put(0x00000071L, "CKR_MECHANISM_PARAM_INVALID");
        cnMap.put(0x00000082L, "CKR_OBJECT_HANDLE_INVALID");
        cnMap.put(0x00000090L, "CKR_OPERATION_ACTIVE");
        cnMap.put(0x00000091L, "CKR_OPERATION_NOT_INITIALIZED");
        cnMap.put(0x000000A0L, "CKR_PIN_INCORRECT");
        cnMap.put(0x000000A1L, "CKR_PIN_INVALID");
        cnMap.put(0x000000A2L, "CKR_PIN_LEN_RANGE");
        cnMap.put(0x000000A3L, "CKR_PIN_EXPIRED");
        cnMap.put(0x000000A4L, "CKR_PIN_LOCKED");
        cnMap.put(0x000000B0L, "CKR_SESSION_CLOSED");
        cnMap.put(0x000000B1L, "CKR_SESSION_COUNT");
        cnMap.put(0x000000B3L, "CKR_SESSION_HANDLE_INVALID");
        cnMap.put(0x000000B4L, "CKR_SESSION_PARALLEL_NOT_SUPPORTED");
        cnMap.put(0x000000B5L, "CKR_SESSION_READ_ONLY");
        cnMap.put(0x000000B6L, "CKR_SESSION_EXISTS");
        cnMap.put(0x000000B7L, "CKR_SESSION_READ_ONLY_EXISTS");
        cnMap.put(0x000000B8L, "CKR_SESSION_READ_WRITE_SO_EXISTS");
        cnMap.put(0x000000C0L, "CKR_SIGNATURE_INVALID");
        cnMap.put(0x000000C1L, "CKR_SIGNATURE_LEN_RANGE");
        cnMap.put(0x000000D0L, "CKR_TEMPLATE_INCOMPLETE");
        cnMap.put(0x000000D1L, "CKR_TEMPLATE_INCONSISTENT");
        cnMap.put(0x000000E0L, "CKR_TOKEN_NOT_PRESENT");
        cnMap.put(0x000000E1L, "CKR_TOKEN_NOT_RECOGNIZED");
        cnMap.put(0x000000E2L, "CKR_TOKEN_WRITE_PROTECTED");
        cnMap.put(0x000000F0L, "CKR_UNWRAPPING_KEY_HANDLE_INVALID");
        cnMap.put(0x000000F1L, "CKR_UNWRAPPING_KEY_SIZE_RANGE");
        cnMap.put(0x000000F2L, "CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT");
        cnMap.put(0x00000100L, "CKR_USER_ALREADY_LOGGED_IN");
        cnMap.put(0x00000101L, "CKR_USER_NOT_LOGGED_IN");
        cnMap.put(0x00000102L, "CKR_USER_PIN_NOT_INITIALIZED");
        cnMap.put(0x00000103L, "CKR_USER_TYPE_INVALID");
        cnMap.put(0x00000104L, "CKR_USER_ANOTHER_ALREADY_LOGGED_IN");
        cnMap.put(0x00000105L, "CKR_USER_TOO_MANY_TYPES");
        cnMap.put(0x00000110L, "CKR_WRAPPED_KEY_INVALID");
        cnMap.put(0x00000112L, "CKR_WRAPPED_KEY_LEN_RANGE");
        cnMap.put(0x00000113L, "CKR_WRAPPING_KEY_HANDLE_INVALID");
        cnMap.put(0x00000114L, "CKR_WRAPPING_KEY_SIZE_RANGE");
        cnMap.put(0x00000115L, "CKR_WRAPPING_KEY_TYPE_INCONSISTENT");
        cnMap.put(0x00000120L, "CKR_RANDOM_SEED_NOT_SUPPORTED");
        cnMap.put(0x00000121L, "CKR_RANDOM_NO_RNG");
        cnMap.put(0x00000130L, "CKR_DOMAIN_PARAMS_INVALID");
        cnMap.put(0x00000150L, "CKR_BUFFER_TOO_SMALL");
        cnMap.put(0x00000160L, "CKR_SAVED_STATE_INVALID");
        cnMap.put(0x00000170L, "CKR_INFORMATION_SENSITIVE");
        cnMap.put(0x00000180L, "CKR_STATE_UNSAVEABLE");
        cnMap.put(0x00000190L, "CKR_CRYPTOKI_NOT_INITIALIZED");
        cnMap.put(0x00000191L, "CKR_CRYPTOKI_ALREADY_INITIALIZED");
        cnMap.put(0x000001A0L, "CKR_MUTEX_BAD");
        cnMap.put(0x000001A1L, "CKR_MUTEX_NOT_LOCKED");
        cnMap.put(0x000001B0L, "CKR_NEW_PIN_MODE");
        cnMap.put(0x000001B1L, "CKR_NEXT_OTP");
        cnMap.put(0x00000200L, "CKR_FUNCTION_REJECTED");
        cnMap.put(0x80000000L, "CKR_VENDOR_DEFINED");
    }

    public static String getName(long rv) {
        String rvName = cnMap.get(rv);
        if (rvName == null) {
            rvName = ToString.toHexString((int) rv);
        }
        return rvName;
    }

    public static long getCode(String rvName) {
        Long rvCode = ncMap.get(rvName);
        if (rvCode == null) {
            throw new IllegalArgumentException("Unknown Cryptoki result value name '" + rvName + "'");
        }
        return rvCode;
    }

    public static final long CKR_OK = 0x00000000L;
    public static final long CKR_CANCEL = 0x00000001L;
    public static final long CKR_HOST_MEMORY = 0x00000002L;
    public static final long CKR_SLOT_ID_INVALID = 0x00000003L;
    public static final long CKR_GENERAL_ERROR = 0x00000005L;
    public static final long CKR_FUNCTION_FAILED = 0x00000006L;
    public static final long CKR_ARGUMENTS_BAD = 0x00000007L;
    public static final long CKR_NO_EVENT = 0x00000008L;
    public static final long CKR_NEED_TO_CREATE_THREADS = 0x00000009L;
    public static final long CKR_CANT_LOCK = 0x0000000AL;
    public static final long CKR_ATTRIBUTE_READ_ONLY = 0x00000010L;
    public static final long CKR_ATTRIBUTE_SENSITIVE = 0x00000011L;
    public static final long CKR_ATTRIBUTE_TYPE_INVALID = 0x00000012L;
    public static final long CKR_ATTRIBUTE_VALUE_INVALID = 0x00000013L;
    public static final long CKR_DATA_INVALID = 0x00000020L;
    public static final long CKR_DATA_LEN_RANGE = 0x00000021L;
    public static final long CKR_DEVICE_ERROR = 0x00000030L;
    public static final long CKR_DEVICE_MEMORY = 0x00000031L;
    public static final long CKR_DEVICE_REMOVED = 0x00000032L;
    public static final long CKR_ENCRYPTED_DATA_INVALID = 0x00000040L;
    public static final long CKR_ENCRYPTED_DATA_LEN_RANGE = 0x00000041L;
    public static final long CKR_FUNCTION_CANCELED = 0x00000050L;
    public static final long CKR_FUNCTION_NOT_PARALLEL = 0x00000051L;
    public static final long CKR_FUNCTION_NOT_SUPPORTED = 0x00000054L;
    public static final long CKR_KEY_HANDLE_INVALID = 0x00000060L;
    public static final long CKR_KEY_SIZE_RANGE = 0x00000062L;
    public static final long CKR_KEY_TYPE_INCONSISTENT = 0x00000063L;
    public static final long CKR_KEY_NOT_NEEDED = 0x00000064L;
    public static final long CKR_KEY_CHANGED = 0x00000065L;
    public static final long CKR_KEY_NEEDED = 0x00000066L;
    public static final long CKR_KEY_INDIGESTIBLE = 0x00000067L;
    public static final long CKR_KEY_FUNCTION_NOT_PERMITTED = 0x00000068L;
    public static final long CKR_KEY_NOT_WRAPPABLE = 0x00000069L;
    public static final long CKR_KEY_UNEXTRACTABLE = 0x0000006AL;
    public static final long CKR_MECHANISM_INVALID = 0x00000070L;
    public static final long CKR_MECHANISM_PARAM_INVALID = 0x00000071L;
    public static final long CKR_OBJECT_HANDLE_INVALID = 0x00000082L;
    public static final long CKR_OPERATION_ACTIVE = 0x00000090L;
    public static final long CKR_OPERATION_NOT_INITIALIZED = 0x00000091L;
    public static final long CKR_PIN_INCORRECT = 0x000000A0L;
    public static final long CKR_PIN_INVALID = 0x000000A1L;
    public static final long CKR_PIN_LEN_RANGE = 0x000000A2L;
    public static final long CKR_PIN_EXPIRED = 0x000000A3L;
    public static final long CKR_PIN_LOCKED = 0x000000A4L;
    public static final long CKR_SESSION_CLOSED = 0x000000B0L;
    public static final long CKR_SESSION_COUNT = 0x000000B1L;
    public static final long CKR_SESSION_HANDLE_INVALID = 0x000000B3L;
    public static final long CKR_SESSION_PARALLEL_NOT_SUPPORTED = 0x000000B4L;
    public static final long CKR_SESSION_READ_ONLY = 0x000000B5L;
    public static final long CKR_SESSION_EXISTS = 0x000000B6L;
    public static final long CKR_SESSION_READ_ONLY_EXISTS = 0x000000B7L;
    public static final long CKR_SESSION_READ_WRITE_SO_EXISTS = 0x000000B8L;
    public static final long CKR_SIGNATURE_INVALID = 0x000000C0L;
    public static final long CKR_SIGNATURE_LEN_RANGE = 0x000000C1L;
    public static final long CKR_TEMPLATE_INCOMPLETE = 0x000000D0L;
    public static final long CKR_TEMPLATE_INCONSISTENT = 0x000000D1L;
    public static final long CKR_TOKEN_NOT_PRESENT = 0x000000E0L;
    public static final long CKR_TOKEN_NOT_RECOGNIZED = 0x000000E1L;
    public static final long CKR_TOKEN_WRITE_PROTECTED = 0x000000E2L;
    public static final long CKR_UNWRAPPING_KEY_HANDLE_INVALID = 0x000000F0L;
    public static final long CKR_UNWRAPPING_KEY_SIZE_RANGE = 0x000000F1L;
    public static final long CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT = 0x000000F2L;
    public static final long CKR_USER_ALREADY_LOGGED_IN = 0x00000100L;
    public static final long CKR_USER_NOT_LOGGED_IN = 0x00000101L;
    public static final long CKR_USER_PIN_NOT_INITIALIZED = 0x00000102L;
    public static final long CKR_USER_TYPE_INVALID = 0x00000103L;
    public static final long CKR_USER_ANOTHER_ALREADY_LOGGED_IN = 0x00000104L;
    public static final long CKR_USER_TOO_MANY_TYPES = 0x00000105L;
    public static final long CKR_WRAPPED_KEY_INVALID = 0x00000110L;
    public static final long CKR_WRAPPED_KEY_LEN_RANGE = 0x00000112L;
    public static final long CKR_WRAPPING_KEY_HANDLE_INVALID = 0x00000113L;
    public static final long CKR_WRAPPING_KEY_SIZE_RANGE = 0x00000114L;
    public static final long CKR_WRAPPING_KEY_TYPE_INCONSISTENT = 0x00000115L;
    public static final long CKR_RANDOM_SEED_NOT_SUPPORTED = 0x00000120L;
    public static final long CKR_RANDOM_NO_RNG = 0x00000121L;
    public static final long CKR_DOMAIN_PARAMS_INVALID = 0x00000130L;
    public static final long CKR_BUFFER_TOO_SMALL = 0x00000150L;
    public static final long CKR_SAVED_STATE_INVALID = 0x00000160L;
    public static final long CKR_INFORMATION_SENSITIVE = 0x00000170L;
    public static final long CKR_STATE_UNSAVEABLE = 0x00000180L;
    public static final long CKR_CRYPTOKI_NOT_INITIALIZED = 0x00000190L;
    public static final long CKR_CRYPTOKI_ALREADY_INITIALIZED = 0x00000191L;
    public static final long CKR_MUTEX_BAD = 0x000001A0L;
    public static final long CKR_MUTEX_NOT_LOCKED = 0x000001A1L;
    public static final long CKR_NEW_PIN_MODE = 0x000001B0L;
    public static final long CKR_NEXT_OTP = 0x000001B1L;
    public static final long CKR_FUNCTION_REJECTED = 0x00000200L;
    public static final long CKR_VENDOR_DEFINED = 0x80000000L;

}
